package com.fenxiangle.yueding.common.util;
import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

public class RxKeyboardTool {
    public RxKeyboardTool() {
    }

    public static void hideSoftInput(Activity activity) {
        View view = activity.getWindow().peekDecorView();
        if (view != null) {
            InputMethodManager inputmanger = (InputMethodManager)activity.getSystemService("input_method");
            inputmanger.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }

    }

    public static void hideKeyboard(Activity activity, View view) {
        InputMethodManager imm = (InputMethodManager)activity.getSystemService("input_method");
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }

    public static void hideSoftInput(Context context, EditText edit) {
        edit.clearFocus();
        InputMethodManager inputmanger = (InputMethodManager)context.getSystemService("input_method");
        inputmanger.hideSoftInputFromWindow(edit.getWindowToken(), 0);
    }

    public static void clickBlankArea2HideSoftInput0() {
        Log.i("tips", "U should copy the following code.");
    }

    public static void clickBlankArea2HideSoftInput1() {
        Log.i("tips", "U should copy the following code.");
    }

    public static void showSoftInput(Context context, EditText edit) {
        edit.setFocusable(true);
        edit.setFocusableInTouchMode(true);
        edit.requestFocus();
        InputMethodManager inputManager = (InputMethodManager)context.getSystemService("input_method");
        inputManager.showSoftInput(edit, 0);
    }

    public static void toggleSoftInput(Context context, EditText edit) {
        edit.setFocusable(true);
        edit.setFocusableInTouchMode(true);
        edit.requestFocus();
        InputMethodManager inputManager = (InputMethodManager)context.getSystemService("input_method");
        inputManager.toggleSoftInput(2, 0);
    }
}